package com.personal.gateway.config;

import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.KubeConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileReader;
import java.util.Objects;

/**
 * @program: FlinkGateway
 * @description:
 * @author: yangliao
 * @create: 2021-07-09 10:39
 */
@Configuration
public class K8sConfig {

    @Resource
    private ValueConfig valueConfig;

    @Bean
    public CoreV1Api coreV1Api() throws Exception {
        // 加载k8s,confg
        ApiClient client = ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(valueConfig.getKubeConfigPath()))).build();
        // 将加载confi的client设置为默认的client
        io.kubernetes.client.openapi.Configuration.setDefaultApiClient(client);
        // 创建一个api
        return new CoreV1Api();

    }

}
